package com.customization.huangwm.formmode.osahc;

import java.util.Map;

import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;

import weaver.general.Util;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.workflow.WorkflowVersion;

/**
 * @author Huangwm
 * @package com.customization.huangwm.formmode.osahc
 * @description 职安健建模创建流程工具
 */
public class SendMsg {
    private Log log = new LogFactory().getLog("custom_huangwm");

    public String[] main_fields = new String[]{"rwmbnr", "tjnr", "scwjtp", "bz", "dyctxrq", "dectxrq", "dsctxrq",
            "fzr", "fzrbm", "xzgjry", "fqr", "fqrq", "nf"};
    //上下的字段要一致
    public String main_fqr = "fqr";
    public String main_fqrq = "fqrq";
    public String main_rwmbnr = "rwmbnr";
    public String main_tjnr = "tjnr";
    public String main_scwjtp = "scwjtp";
    public String main_bz = "bz";
    public String main_dyctxrq = "dyctxrq";
    public String main_dectxrq = "dectxrq";
    public String main_dsctxrq = "dsctxrq";
    public String main_fzr = "fzr";
    public String main_fzrbm = "fzrbm";
    public String main_xzgjry = "xzgjry";
    public String main_nf = "nf";


    /**
     * 设置提醒流程流转信息
     *
     * @param userid  创建人
     * @param title   标题
     * @param mainMap 主表数据
     * @return RequestInfo
     * @throws Exception
     */
    public RequestInfo setRequestInfo(String userid, String title, Map<String, String> mainMap, String workflowid) throws Exception {
        RequestInfo requestInfo = new RequestInfo();
        String activeWFID = WorkflowVersion.getActiveVersionWFID(workflowid);
        log.info("获取到的活动版本workflowid  " + activeWFID);
        requestInfo.setWorkflowid(activeWFID);
        requestInfo.setIsNextFlow("1");
        requestInfo.setCreatorid(userid);
        requestInfo.setDescription(title);
        requestInfo.setMainTableInfo(setMainTableInfo(mainMap));
        return requestInfo;
    }

    /**
     * 设置主表字段
     *
     * @param fieldName
     * @param fieldValue
     * @return
     */
    public Property setMainField(String fieldName, String fieldValue) {
        Property field = new Property();
        field.setName(fieldName);
        field.setValue(fieldValue);
        return field;
    }


    /**
     * 设置归还流程主表数据
     *
     * @param params
     * @return
     */
    public MainTableInfo setMainTableInfo(Map<String, String> params) {
        log.info("开始设置 職安健合同之跟進項提交表 流程信息");
        log.info(params);
        MainTableInfo mainTableInfo = new MainTableInfo();
        /*
        for(int i=0;i<main_fields.length;i++){
        	log.info("设置字段："+main_fields[i]+"  设置值："+params.get(main_fields[i]));
            mainTableInfo.addProperty(setMainField(main_fields[i], Util.null2String(params.get(main_fields[i]))));
        }
        */
        mainTableInfo.addProperty(setMainField(main_fqr, Util.null2String(params.get(main_fqr))));
        mainTableInfo.addProperty(setMainField(main_fqrq, Util.null2String(params.get(main_fqrq))));
        mainTableInfo.addProperty(setMainField(main_nf, Util.null2String(params.get(main_nf))));
        mainTableInfo.addProperty(setMainField(main_rwmbnr, Util.null2String(params.get(main_rwmbnr))));
        mainTableInfo.addProperty(setMainField(main_tjnr, Util.null2String(params.get(main_tjnr))));
        mainTableInfo.addProperty(setMainField(main_dyctxrq, Util.null2String(params.get(main_dyctxrq))));
        mainTableInfo.addProperty(setMainField(main_dectxrq, Util.null2String(params.get(main_dectxrq))));
        mainTableInfo.addProperty(setMainField(main_dsctxrq, Util.null2String(params.get(main_dsctxrq))));
        mainTableInfo.addProperty(setMainField(main_fzr, Util.null2String(params.get(main_fzr))));
        mainTableInfo.addProperty(setMainField(main_fzrbm, Util.null2String(params.get(main_fzrbm))));
        log.info("流程主表设置完成");
        return mainTableInfo;
    }

}
